﻿using ChurchDiary.Common;
using ChurchDiary.DAL.Contract;
using ChurchDiary.DAL.Methods;
using ChurchDiary.TableEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChurchDiary.BLL
{
    public class BLL_Menu
    {
        public string GetMenuHTML(EntityMenuList lst)
        {
            string MenuString = "<ul class=\"list-unstyled navigation\">";
            for (int i = 0; i <= lst.entitymenucategory.Count - 1; i++)
            {
                MenuString += "<li class=\"header\">" + lst.entitymenucategory[i].MenuCategoryName + "</li>";
                for (int j = 0; j <= lst.entitymainmenu.Count - 1; j++)
                {
                    if (lst.entitymenucategory[i].MenuCategoryId == lst.entitymainmenu[j].MenuCategoryid)
                    {
                        MenuString += "<li class=\"panel\">";
                        MenuString += "<a class='collapsed' role='button' data-toggle='collapse' data-parent='.navigation' href='#" + lst.entitymainmenu[j].MenuName.Replace(" ", "") + "' aria-expanded='false' aria-controls='collapse2'><i class='" + lst.entitymainmenu[j].MenuIcon + "'></i> " + lst.entitymainmenu[j].MenuName + "</a>";
                        MenuString += "<ul class=\"list-unstyled collapse\" id=" + lst.entitymainmenu[j].MenuName.Replace(" ", "") + ">";
                        for (int k = 0; k <= lst.entitysubMenu.Count - 1; k++)
                        {
                            if (lst.entitysubMenu[k].MainMenuID == lst.entitymainmenu[j].MainMenuID)
                            {
                                if (lst.entitysubMenu[k].ActionName != "")
                                {
                                    MenuString += "<li><a href=../../../" + lst.entitysubMenu[k].Area + "/" + lst.entitysubMenu[k].Controllername + "/" + lst.entitysubMenu[k].ActionName + "><span>" + lst.entitysubMenu[k].SubMenuName + "</span></a></li>";
                                }
                                else
                                {
                                    MenuString += "<li><a href=../../../" + lst.entitysubMenu[k].Area + "/" + lst.entitysubMenu[k].Controllername + "><span>" + lst.entitysubMenu[k].SubMenuName + "</span></a></li>";
                                }
                            }
                        }
                        MenuString += "</ul>";
                        MenuString += "</li>";
                    }
                }
            }
            MenuString += "</ul>";
            return MenuString;
        }
        public string GetMenuTable(EntityMenuList lst)
        {
            string MenuString = "";
            for (int i = 0; i <= lst.entitymenucategory.Count - 1; i++)
            {
                MenuString += "<div class=\"\">";
                MenuString += "<h3>" + lst.entitymenucategory[i].MenuCategoryName + "</h3>";
                for (int j = 0; j <= lst.entitymainmenu.Count - 1; j++)
                {
                    if (lst.entitymenucategory[i].MenuCategoryId == lst.entitymainmenu[j].MenuCategoryid)
                    {
                        MenuString += "<ul class=\"nav side-menu\"><li>";
                        MenuString += "<a><i class='" + lst.entitymainmenu[j].MenuIcon + "'></i>" + lst.entitymainmenu[j].MenuName + "<span class=\"fa fa-chevron-down\"></span></a>";
                        MenuString += "<ul class=\"nav child_menu\" style=\"display: none\">";
                        for (int k = 0; k <= lst.entitysubMenu.Count - 1; k++)
                        {
                            if (lst.entitysubMenu[k].MainMenuID == lst.entitymainmenu[j].MainMenuID)
                            {
                                if (lst.entitysubMenu[k].ActionName != "")
                                {
                                    MenuString += "<li><a href=../../../" + lst.entitysubMenu[k].Area + "/" + lst.entitysubMenu[k].Controllername + "/" + lst.entitysubMenu[k].ActionName + ">" + lst.entitysubMenu[k].SubMenuName + "</a></li>";
                                }
                                else
                                {
                                    MenuString += "<li><a href=../../../" + lst.entitysubMenu[k].Area + "/" + lst.entitysubMenu[k].Controllername + ">" + lst.entitysubMenu[k].SubMenuName + "</a></li>";
                                }
                            }
                        }
                        MenuString += "</ul>";
                        MenuString += "</li></ul>";
                    }
                }
                MenuString += "</div>";
            }
            return MenuString;
        }
        public EntityMenuList GetMenu()
        {
            IDALMenu Menu = new DAL_Menu();
            return Menu.GetAllMenus(Current.IsSuperAdmin, Current.Userid);
        }
        public string AddSubMenus(EntitySubMenu SubMenu)
        {
            IDALMenu Menu = new DAL_Menu();
            return Menu.InsertSubMenu(SubMenu);
        }
        public string UpdateSubMenus(EntitySubMenu SubMenu)
        {
            IDALMenu Menu = new DAL_Menu();
            return Menu.UpdateSubMenu(SubMenu);
        }
        public string DeleteSubMenus(int SubMenuId)
        {
            IDALMenu Menu = new DAL_Menu();
            return Menu.DeleteSubMenu(SubMenuId);
        }
        public List<EntitySubMenu> GetSubMenus()
        {
            IDALMenu Menu = new DAL_Menu();
            return Menu.GetSubMenus();
        }
        public EntitySubMenu GetSubMenu(int MenuID)
        {
            IDALMenu Menu = new DAL_Menu();
            return Menu.GetSubMenu(MenuID);
        }
        public List<EntityMenuCategory> GetMenuCategory()
        {
            IDALMenu Menu = new DAL_Menu();
            return Menu.GetMenuCategory();
        }
        public List<EntityMainMenu> GetMainMenus(int Categoryid)
        {
            IDALMenu Menu = new DAL_Menu();
            return Menu.GetMainMenus(Categoryid);
        }
    }
}
